package com.matrix.java.chap_05;

import java.util.Scanner;

/*
    商业：检测 ISBN 13
 */
public class Ex5_47 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("Enter the first 12 digits of an ISBN-13 as a string: ");
        String str = input.next();
        long num = Long.valueOf(str);
        int result = 0;
        if (str.length() != 12) {
            System.out.println("illegal");
        }
        for (int i = 0; i < str.length(); i++) {
            long d = num % 10;
            num /= 10;
            if (i % 2 == 0) {
                result += 3 * d;
            } else {
                result += d;
            }
        }
        int d13 = 10 - result % 10;
        if (d13 == 10) {
            d13 = 0;
        }
        System.out.println("The ISBN-13 number is " + str + d13);
        input.close();
    }
}
